package com.szjz.rabbitmq.client.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.szjz.rabbitmq.client.util.RabbitMQUtils;

import java.io.IOException;

/**
 * @author 史博
 * @desc topic 动态路由
 * @date 2020/8/25 5:41 下午 周二
 */
public class Provider {

    public static void main(String[] args) throws IOException {
        // 获取链接创建通道
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        // 声明交换机
        // 参数1：交换机名称
        // 参数2：交换机类型
        String exchangeName = "topics";
        channel.exchangeDeclare(exchangeName, "topic");
        // 发送消息
        String routingKey = "super.user.info";
        channel.basicPublish(exchangeName, routingKey, null, "topic message".getBytes());
        RabbitMQUtils.close(connection,channel);
    }
}
